/// Business logic class defined by OpenAPI in HCC.Interface.WS.spec<br/>
/// Updated May 16, 2023 04:05:33
Class HCC.Interface.WS.impl Extends %REST.Impl [ ProcedureBlock ]
{

/// If ExposeServerExceptions is true, then details of internal errors will be exposed.
Parameter ExposeServerExceptions = 1;

/// 获取html格式的共享文档<br/>
/// The method arguments hold values for:<br/>
///     Id, 文档Id<br/>
ClassMethod GetDocumentHTML(Id As %String) As %Stream.Object
{

    #dim tSC As %Status = $$$OK    
    #dim e As %Exception.AbstractException    
    Try     
    {    
        Set pDocNo = $ZSTRIP(Id, "<>W"),tHTML=""
        Set tSC = ##class(HCC.Util).GetDocHTML(pDocNo,.tHTML)
    } 
    Catch ex 
    {        
        Return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("获取HTML文档失败", ex.AsStatus(),500)
    }    
    Return tHTML
}

/// 获取指定id的共享文档<br/>
/// The method arguments hold values for:<br/>
///     Id, 文档Id<br/>
ClassMethod GetDocument(Id As %String) As %Stream.Object
{
   Try {
    Set reText=""
     &SQL(
    select Content into :tRet 
    from HCC_DocRepository.LatestDocs
    where DocId=:Id
    )
    If SQLCODE = 0
    {
	     Do ##class(HCC.Utils.Anonymization).Do(tRet,.reText)
 			 
    }
    Else
    {
        Set response={}
        Set response.msg="未查找到文档号:"_Id
        Do ..%SetStatusCode(404)
        Return response
    }
   }
   Catch ex {
     Return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("获取文档失败", ex.AsStatus(),500)
   }
   Return reText
}

/// 删除指定id的共享文档<br/>
/// The method arguments hold values for:<br/>
///     Id, 文档Id<br/>
ClassMethod DeleteDoc(Id As %String) As %Stream.Object
{
    Try {
        Return ##class(HCC.SQL.Tools).ClearDoc(Id)
    }
    Catch ex {
        Return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("删除文档失败", ex.AsStatus(),500)
    }
}

/// 生成目标id的共享文档<br/>
/// The method arguments hold values for:<br/>
///     Id, 文档Id<br/>
ClassMethod GenerateDocFromSQL(Id As %String) As %Stream.Object
{
    Try {
        Return ##class(HCC.Util).PushDocGenQueue(Id)
    }
    Catch ex {
        Return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("生成文档失败", ex.AsStatus(),500)
    }
}

/// 获取数据元
ClassMethod ListDE() As %Stream.Object
{
 
    Try {
         &SQL(
        SELECT JSON_ARRAYAGG(
        JSON_OBJECT(
        'name':name, 
        'category':category, 
        'description':description, 
        'format':format, 
        'valueset':valueset, 
        'datatype':datatype
        ))
      INTO :tRet
      FROM WS.WSDataElement
    )
    }
    Catch ex {
        Set tSC=ex.AsStatus()
    }
    Return tRet
}

/// 更新/新增数据元<br/>
/// The method arguments hold values for:<br/>
///     body, 数据元<br/>
ClassMethod PutDE(body As %Stream.Object) As %Stream.Object
{
     Try 
    {
        #; Parse the content (JSON array)
        #dim tDEObj As %DynamicObject
        Set tDEObj=##class(%DynamicObject).%FromJSON(body)
        
        If 'tDEObj.%IsA("%DynamicObject")
        {
            return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("数据元格式不正确",$$$OK,400) 
        }
        /*
        'name':name, 
        'category':category, 
        'description':description, 
        'format':format, 
        'valueset':valueset, 
        'datatype':datatype*/
        
        /*
        Parameter Category = "标识";
        Parameter Description = "报卡类别代码";
        Parameter Format = "N1";
        Parameter ValueSetDisplay = "1:初次报告;2:订正报告;";
        Parameter ValueSet = "DE01.00.002.00";
        Parameter WSDT = "S2";
        Property Value As WS.DT.CodedString(ValueSet = "DE01.00.002.00");
        */

        
        Set tName=$ZCVT(tDEObj.name,"I","UTF8"), 
        tCategory =tDEObj.category,
        tFormat = tDEObj.format, 
        tDatatype = tDEObj.datatype, 
        tValueset = tDEObj.valueset,
        tDescription = tDEObj.description
        If (tName="")||(tDatatype="")||(tFormat="")
        {
            return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("数据元名称、数据类型、数据格式不能为空",$$$OK,400) 
        } 
        
        Set tDEClassName = "WS.DE."_$Replace(tName,".","")
        Set tDEExist=##class(%Dictionary.ClassDefinition).%ExistsId(tDEClassName)
        If ('tDEExist) 
        {
            Set tDEClass=##class(%Dictionary.ClassDefinition).%New()
            Set tDEClass.Super = "WS.DE.Base"
            Set tP1=##class(%Dictionary.ParameterDefinition).%New()
            Set tP1.Name="Category"
            Set tP1.Default = ""
            Do tDEClass.Parameters.Insert(tP1)
            
            Set tP2=##class(%Dictionary.ParameterDefinition).%New()
            Set tP2.Name="Description"
            Set tP2.Default = ""
            Do tDEClass.Parameters.Insert(tP2)
            
            Set tP3=##class(%Dictionary.ParameterDefinition).%New()
            Set tP3.Name="Format"
            Set tP3.Default = ""
            Do tDEClass.Parameters.Insert(tP3)
           
            Set tP4=##class(%Dictionary.ParameterDefinition).%New()
            Set tP4.Name="ValueSet"
            Set tP4.Default = ""
            Do tDEClass.Parameters.Insert(tP4)
            
            Set tP5=##class(%Dictionary.ParameterDefinition).%New()
            Set tP5.Name="WSDT"
            Set tP5.Default = ""
            Do tDEClass.Parameters.Insert(tP5)
            
            Set tPp=##class(%Dictionary.PropertyDefinition).%New()
            Set tPp.Name="Value"
            Set tPp.Type="%String"
            set tDEClass.Name = tDEClassName
            Do tDEClass.Properties.Insert(tPp)
            Do tDEClass.%Save()
        }
        
        // 如果是值集约束类型
        If (tValueset'="") && ((tDatatype = "S2") ||(tDatatype = "S3"))
        {
            Do ..SetDEClass(tDEClassName,tCategory,tDescription,tFormat,tValueset,tDatatype)
        }
        // 如果是布尔类型
        elseIf (tValueset="") && (tDatatype = "L")
        {
            Do ..SetDEClass(tDEClassName,tCategory,tDescription,tFormat,tValueset,tDatatype)
        }
        // 如果是字符串类型
        elseIf (tValueset="") && (tDatatype = "S1")
        {
            Do ..SetDEClass(tDEClassName,tCategory,tDescription,tFormat,tValueset,tDatatype)
        }
        // 如果是日期类型
        elseIf (tValueset="") && (tDatatype = "D8")
        {
            Do ..SetDEClass(tDEClassName,tCategory,tDescription,tFormat,tValueset,tDatatype)
        }
        // 如果是时间戳类型
        elseIf (tValueset="") && (tDatatype = "DT")
        {
            Do ..SetDEClass(tDEClassName,tCategory,tDescription,tFormat,tValueset,tDatatype)
        }
        // 其它组合错误
        else
        {
            return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("数据元类型与值集不匹配",$$$OK,400)
        }
        
        //检查是否tDEClass发生了变化
        //If (tDEClass.Modified)
        //{
            //Do tDEClass.%Save()
            Do $System.OBJ.Compile(tDEClassName,"-d")
        //}
    }
    catch e
    {
        return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("创建数据元失败",e.AsStatus(),500)
    }
    Return 1
}

/// 获取指定id数据元<br/>
/// The method arguments hold values for:<br/>
///     Id, 数据元Id<br/>
ClassMethod GetDE(Id As %String) As %Stream.Object
{
    Set tRet=""
    Set tDEName = "WS.DE."_$Replace(Id,".","")
    Try
    { 
        &SQL(
            SELECT JSON_ARRAYAGG(
            JSON_OBJECT(
            'name':name, 
            'category':category, 
            'description':description, 
            'format':format, 
            'valueset':valueset, 
            'datatype':datatype
            ))
          INTO :tRet
          FROM WS.WSDataElement
          WHERE name = :tDEName
        )
        
        If SQLCODE = 100
        {
            return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("获取数据元失败"_Id_"不存在", $$$OK,404)
        }
    }
    Catch (e)
    {
        return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("获取数据元失败", e.AsStatus(),500)
    }
    return tRet
}

/// 获取全部值集信息
ClassMethod ListValueSet() As %Stream.Object
{
    Try {
        return ##class(HCC.Util).ListVS()
    }
    Catch ex {
        return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("获取值集失败", ex.AsStatus(),500)
    }
}

/// 获取特定值集<br/>
/// The method arguments hold values for:<br/>
///     Id, 值集Id<br/>
ClassMethod ListValueSetItems(Id As %String) As %Stream.Object
{
   Try {
    Set tSC = $$$OK
    Set tGol = "^WS.VS."_$replace($ZStrip(Id, "<>W"),$C(10),"")
    If $D(@tGol)=0
    {
        Set tMsg = "值集:"_Id_"不存在"
        Return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse(tMsg,$$$OK,404)
    }
    
    Set tSub = "", tOutput = ##class(%DynamicArray).%New()
    Set tSub = $O(@tGol@(tSub))
    While tSub '=""
    {
        Set tItem = ##class(%DynamicObject).%New()
        Set tItem.Key = tSub, tItem.Value = $G(@tGol@(tSub))
        Do tOutput.%Push(tItem)
        Set tSub = $O(@tGol@(tSub))
    }
   }
   Catch ex {
        return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("获取值集元素失败", ex.AsStatus(),500)
   }
   return tOutput
}

/// 删除特定值集<br/>
/// The method arguments hold values for:<br/>
///     Id, 值集Id<br/>
ClassMethod DeleteValueSet(Id As %String) As %Stream.Object
{
    Try {
        Set tSC = $$$OK
    Set tGol = "^WS.VS."_$replace(Id,".","")
    set exist = $data(@tGol)
    If (exist'=1)&&(exist'=10)
    {
        Set tMsg = "值集:"_Id_"不存在"
        Return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse(tMsg,$$$OK,404)
    }
    k @tGol
    
    }
    Catch ex {
        return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("删除值集失败", ex.AsStatus(),500)
    }
    Return tSC
}

/// 更新/新增特定值集<br/>
/// The method arguments hold values for:<br/>
///     Id, 值集Id<br/>
///     body, 值集<br/>
ClassMethod PutValueSetItem(Id As %String, body As %Stream.Object) As %Stream.Object
{
    Set tSC = $$$OK,tVS = $replace($ZStrip(Id, "<>W"),$C(10),"")
    If tVS =""
    {
        Set tMsg = "值集Id不能为空"
        Return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse(tMsg,$$$OK,400)
    }
    Set tGol = "^WS.VS."_$Replace(tVS,".","")
    Try 
    {
        #; Ensure we are only passed json
        #; Parse the content (JSON array)
        #dim tItemArray As %DynamicArray
        Set tItemArray=##class(%DynamicArray).%FromJSON(body)
       // Set ^TestLog($I(^TestLog))="ArraySize="_tItemArray.%Size()
        For tI=0:1:tItemArray.%Size()-1 
        {
            #; Get the KV object
            Set tKV=tItemArray.%Get(tI)
            If 'tKV.%IsA("%DynamicObject")
            {
                return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("解析值集失败", $$$OK,400)  
            }
            
            //Set tSub=tKV.Key, tValue = $ZCVT(tKV.Value,"O","UTF8")
            set tSub=tKV.Key 
            
            set tValue=tKV.Value
            
            If (tSub="")||(tValue="")
            {
                return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("值集元素不能为空", $$$OK,400)   
            } 
            Set tTemArray(tSub)=tValue
        }
        Merge @tGol=tTemArray
        //Merge ^TestLog($I(^TestLog))=tTemArray
        kill tTemArray
    }
    catch (e)
    {
        return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("更新值集失败", e.AsStatus(),500)
    }
    Return tSC
}

/// 获取指定值集指定key的值<br/>
/// The method arguments hold values for:<br/>
///     Id, 值集Id<br/>
///     key, 值集key<br/>
ClassMethod GetValueSetItem(Id As %String, key As %String) As %Stream.Object
{
    Try {
        Set tSC = $$$OK
    Set tGol = "^WS.VS."_$replace(Id,".",""), tSub=key
    If $D(@tGol@(tSub))'=1
    {
        Set tMsg = "值集:"_Id_"不存在"
        Return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse(tMsg,$$$OK,404)
    }
    }
    Catch ex {
        return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("获取值集元素失败", ex.AsStatus(),500)
    }
    Return $G(@tGol@(tSub))
}

/// 删除指定id的值集<br/>
/// The method arguments hold values for:<br/>
///     Id, 值集Id<br/>
///     key, 值集key<br/>
ClassMethod DeleteValueSetItem(Id As %String, key As %String) As %Stream.Object
{
    Try {
        Set tSC = $$$OK
    Set tGol = "^WS.VS."_$replace(Id,".",""), tSub=key
    If $D(@tGol@(tSub))'=1
    {
        Set tMsg = "值集:"_Id_"不存在"
        W tMsg
        Return $$$ERROR(-10001,tMsg)
    }
    k @tGol@(tSub)
    }
    Catch ex {
        return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("删除值集元素失败", ex.AsStatus(),500)
    }
    return tSC
}

/// 获取共享文档章节设置<br/>
/// The method arguments hold values for:<br/>
///     Doctype, 文档类型<br/>
ClassMethod GetDocSections(Doctype As %String) As %Stream.Object
{
    Try {
            #SQLCompile Select=Display 
    &SQL(
    SELECT JSON_ARRAYAGG(JSON_OBJECT('Section':DocumentSection,'Cardinality':Cardinality))
      INTO :tRet
      FROM WS_DOC.DocumentConfig
     WHERE DocumentType=:Doctype
    )
    }
    Catch ex {
        return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("获取共享文档章节设置失败", ex.AsStatus(),500)
    }
    return tRet
}

/// 更新共享文档章节设置<br/>
/// The method arguments hold values for:<br/>
///     Doctype, 文档类型<br/>
///     body, 文档章节设置<br/>
ClassMethod UpdateDocSections(Doctype As %String, body As %Stream.Object) As %Stream.Object
{
    Set tSC = $$$OK,tDocType = $ZStrip(Doctype, "<>W")
    If tDocType =""
    {
        w "请输入文档类型编号"
        Return $$$ERROR(-10001,"请输入文档类型编号")
    }
        
    Try 
    {
        #; Ensure we are only passed json
        If ..%GetHeader("Content-Type")'="application/json"
        {  
            return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("只能接受application/json格式的数据", $$$OK,400) 
        }
        

        #; Parse the content (JSON array)
        #dim tItemArray As %DynamicArray
        Set tItemArray=##class(%DynamicArray).%FromJSON(body)
        
        TStart
        #SQLCompile Select=Display
        //删除原有设置
        &SQL(delete from WS_DOC.DocumentConfig where DocumentType=:tDocType )

        For tI=0:1:tItemArray.%Size()-1 
        {
            #; Get the KV object
            Set tKV=tItemArray.%Get(tI)
            If 'tKV.%IsA("%DynamicObject")
            {
                ;TRollback
                return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("解析章节设置失败", $$$OK,400)   
            }
            //Set tCar=tKV.Cardinality, tSec = $ZCVT(tKV.Section,"I","UTF8")
            Set tCar=tKV.Cardinality, tSec = tKV.Section
            If (tCar="")||(tSec="")
            {
                ;TRollback
                return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("章节设置不能为空", $$$OK,400)     
            } 
          
            // 插入每一条章节约束
            &SQL(Insert or update WS_DOC.DocumentConfig(DocumentType,DocumentSection,Cardinality) 
            values(:tDocType,:tSec,:tCar) )
            If (SQLCODE '=0 )
            {
                Set tSC = $$$ERROR(-10001,"数据错误:"_SQLCODE_" "_%msg)
                return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("更新共享文档章节设置失败", tSC,500)
            }
        }
        // 如果失败，回滚整个事务
        If $$$ISERR(tSC)
        {
            TRollback
        }
        Else
        {
            TCommit
        }
    }
    catch (e)
    {
        TRollback
    }
    Return tSC
}

/// 获取共享文档生成日志
ClassMethod GetHCCLog() As %Stream.Object
{
    Try
    {
        Set tBeginTime = $ZStrip($G(%request.Data("BeginTime",1)), "<>W")
        Set tEndTime = $ZStrip($G(%request.Data("EndTime",1)), "<>W")
        Set tType = $ZStrip($G(%request.Data("Type",1)), "<>W")    
    }
    Catch e
    {
       return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("获取共享文档生成日志失败", e.AsStatus(),500)
    }
    
    Return ##class(HCC.Util).GetHCCLog(tBeginTime,tEndTime,tType)
}

/// 获取病人所有的共享文档编号信息<br/>
/// The method arguments hold values for:<br/>
///     PatNo, 病人号<br/>
ClassMethod GetPatientDocList(PatNo As %String) As %Stream.Object
{
   Try {
    Set tRet = ""
    &SQL(SELECT JSON_ARRAYAGG(JSON_OBJECT('DocId':DocId,'DocName':DocName,'AddDate':AddDate)) into :tRet FROM HCC_DocRepository.LatestDocs WHERE Patient->PatId =:PatNo)
    
    
   }
   Catch ex {
    return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("获取病人所有的共享文档编号信息失败", ex.AsStatus(),500)
   }
   return tRet
}

/// 获取病人数量计数
ClassMethod GetPatientCount() As %Stream.Object
{
    Try {
         Set tRet = ""
    &SQL(SELECT JSON_OBJECT('Count':Count(*)) into :tRet FROM HCC_DocRepository.Patient)
    }
    Catch ex {
      return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("获取病人数量计数失败", ex.AsStatus(),500)
    }
    return tRet
}

/// sql 模型约束检查<br/>
/// The method arguments hold values for:<br/>
///     Table, 表名<br/>
///     Batch, 批次号<br/>
ClassMethod CheckSQLData(Table As %String, Batch As %String) As %Stream.Object
{
    Set tSC = $$$OK
    set response ={}
    Try
    {
        Set tTable = $ZStrip($G(%request.Data("Table",1)), "<>W")
        Set tBatch = $ZStrip($G(%request.Data("Batch",1)), "<>W")
        Set tMsg = "{""msg"":""表:"_tTable_$Case(tBatch,"":"",:",批次:"_tBatch)_" 数据质量检查"
        Set tSC = ##class(HIP.DataGov.Util).CheckContrains(tTable,tBatch)
        If $$$ISERR(tSC) 
        {
            Set tMsg=tMsg_"出现异常,异常原因:"_$system.Status.GetErrorText(tSC)_"""}"
        }
        Else
        {
            Set tMsg=tMsg_"已在后台执行,请随后检查日志HIP_DataGov.Log""}"
        }

        set response.msg=tMsg
    }
    Catch e
    {
        return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("sql 模型约束检查失败", e.AsStatus(),500)
    }
    
    Return response
}

/// 查询患者<br/>
/// The method arguments hold values for:<br/>
///     IDNo, 患者身份证号<br/>
///     Name, 患者姓名<br/>
ClassMethod SearchPatient(IDNo As %String, Name As %String) As %Stream.Object
{
    Set tSC = $$$OK
    Try
    {
        Set tRet="[]"
        Set tIDNo = $ZStrip($G(IDNo), "<>W")
        Set tName = $ZStrip($G(Name), "<>W")
        If (tIDNo'="")&&(tName'="")
        {
            &SQL(SELECT JSON_ARRAYAGG(JSON_OBJECT('IDNo':PatCardId,'Name':PatName)) into :tRet 
            FROM HCC_DocRepository.Patient 
            WHERE PatCardId =:tIDNo
              AND PatName=:tName)
        }
        ElseIf (tIDNo'="")
        {
            &SQL(SELECT JSON_ARRAYAGG(JSON_OBJECT('IDNo':PatCardId,'Name':PatName)) into :tRet 
            FROM HCC_DocRepository.Patient 
            WHERE PatCardId =:tIDNo)

        }
        ElseIf (tName'="")
        {
            &SQL(SELECT JSON_ARRAYAGG(JSON_OBJECT('IDNo':PatCardId,'Name':PatName)) into :tRet 
            FROM HCC_DocRepository.Patient 
            WHERE PatName=:tName)
        }
    }
    Catch e
    {
        return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("查询患者失败", e.AsStatus(),500)
    }
    
    Return tRet
}

/// 共享文档校验<br/>
/// The method arguments hold values for:<br/>
///     DocPath, 文档路径<br/>
ClassMethod CheckDoc(DocPath As %String) As %Stream.Object
{
    #dim tSC As %Status = $$$OK    
    #dim e As %Exception.AbstractException  
    Set %response.ContentType="application/json"  
    Try     
    {    
        Set tDocFile = $ZStrip(DocPath, "<>W")
        Set tFile = "/isc/irishealth/mgr/Backup/Archive/"_tDocFile_".json"
        set tRes= ##class(HCC.Utils.DocValid).CheckDoc(tFile)
    } 
    Catch (e) 
    {        
        return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("共享文档校验失败", e.AsStatus(),500) 
    }    
    Return tRes
}

/// 设置数据元类参数和属性
ClassMethod SetDEClass(pClassName, pCategory, pDescription, pFormat, pValueset, pDatatype) As %Status
{
    Set tSC = $$$OK
    Try
    {
        Set tPa = ##class(%Dictionary.ParameterDefinition).%OpenId(pClassName_"||Category")
        Set tPa.Default=pCategory
        Do tPa.%Save()
        Set tPa = ##class(%Dictionary.ParameterDefinition).%OpenId(pClassName_"||Description")
        Set tPa.Default=pDescription
        Do tPa.%Save()
        Set tPa = ##class(%Dictionary.ParameterDefinition).%OpenId(pClassName_"||Format")
        Set tPa.Default=pFormat
        Do tPa.%Save()
        Set tPa = ##class(%Dictionary.ParameterDefinition).%OpenId(pClassName_"||ValueSet")
        Set tPa.Default=pValueset
        Do tPa.%Save()
        Set tPa = ##class(%Dictionary.ParameterDefinition).%OpenId(pClassName_"||WSDT")
        Set tPa.Default=pDatatype
        Do tPa.%Save()

        Set tPr = ##class(%Dictionary.PropertyDefinition).%Open($LB(pClassName_"||Value"), 0, .tSC)
        Set tPr.Type = $case(pDatatype,"L":"%Boolean","N":"%Integer","D":"WS.DT.Date","DT":"WS.DT.TimeStamp","S1":"%String","S2":"WS.DT.CodedString","S3":"WS.DT.CodedString","T":"%Time","BY":"%Stream.GlobalBinary",:"%String")
        If (pDatatype="D")
        {
            Do tPr.Parameters.SetAt(8,"FORMAT")
        }
        ElseIf (pDatatype="N") && ($Find(pFormat,",")>0)
        {
            Set tPr.Type = "%Decimal", tScale = +$P(pFormat,",",2)
            Do tPr.Parameters.SetAt(tScale,"SCALE")
        }
        ElseIf (pDatatype="N") && ($Find(pFormat,",")=0)
        {
            Set (tTmpDT,tMin,tMax,tScale)=""
            // get value range for %String, %Integer and %Decimal
            Set tSC = ##class(WS.DE.Tools).GetDTDetails(pFormat,.tTmpDT,.tMin,.tMax,.tScale)
            Set:(tMin'=0) tMin = $ZPOWER(10,(tMin-1))
            Set:(tMax'=0) tMax = $ZPOWER(10,tMax)-1
            Do:(tMin'=0) tPr.Parameters.SetAt(tMin,"MINVAL")
            Do:(tMax'=0) tPr.Parameters.SetAt(tMax,"MAXVAL")
        }
        ElseIf (pDatatype="S1") && ($Find(pFormat,",")=0)
        {
            Set (tTmpDT,tMin,tMax,tScale)=""
            // get value range for %String, %Integer and %Decimal
            Set tSC = ##class(WS.DE.Tools).GetDTDetails(pFormat,.tTmpDT,.tMin,.tMax,.tScale)
            Do tPr.Parameters.SetAt(tMax,"MAXLEN")
            Do tPr.Parameters.SetAt(tMin,"MINLEN")
        }
        Do tPr.%Save()
    }
    catch(e)
    {
    }
    Return tSC
}

/// (provide functional description here)<br/>
/// The method arguments hold values for:<br/>
///     body, 文档路径<br/>
ClassMethod DocValid(body As %Stream.Object) As %Stream.Object
{
    #dim tSC As %Status = $$$OK    
    Try
    {
        return ##class(HCC.Utils.DocValid).CheckDocStream(body,0)
    }
    Catch (e) 
    {        
        return ##class(HCC.Utils.ResponseHelper).GetAPIErrorResponse("共享文档校验失败", e.AsStatus(),500)   
    }
}

}
